import {
  CloseOutlined,
  ShrinkOutlined,
  ArrowsAltOutlined,
  MinusOutlined
} from "@ant-design/icons";
import "./index.scss";

const { remote } = window.electron;
const { app } = remote;
const currentWindow = remote.getCurrentWindow();

export default class WindowControls extends React.PureComponent {
  state = {
    isMaximized: currentWindow.isMaximized()
  };

  /**
   * 窗口最大化
   */
  maximize = () => {
    if (currentWindow.isMaximized()) {
      currentWindow.unmaximize();
      this.setState({ isMaximized: false });
    } else {
      currentWindow.maximize();
      this.setState({ isMaximized: true });
    }
  };

  /**
   * 退出关闭 显示退出提示弹窗
   */
  close = () => {
    app.quit();
  };

  render() {
    return (
      <div className="window-controls-container">
        <div
          className="window-icon-bg"
          onClick={() => currentWindow.minimize()}
        >
          <MinusOutlined />
        </div>
        <div className="window-icon-bg" onClick={this.maximize}>
          {this.state.isMaximized && <ShrinkOutlined />}
          {!this.state.isMaximized && <ArrowsAltOutlined />}
        </div>
        <div className="window-icon-bg" onClick={this.close}>
          <CloseOutlined />
        </div>
      </div>
    );
  }
}
